package com.example.jopewars;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class JMainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	private GameEngine game;

	private LocationPanel locationPanel;
	private StatusPanel statusPanel;
	private ActivityPanel activityPanel;
	private MarketplacePanel marketplacePanel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JMainFrame frame = new JMainFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public JMainFrame() {
		setTitle("JopeWars");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 551, 444);

		game = GameEngine.getInstance();

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnGameMenu = new JMenu("Game");
		menuBar.add(mnGameMenu);

		JMenuItem mntmNewGame = new JMenuItem("New");
		mntmNewGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				game.startNewGame();
				locationPanel.startGame();
				activityPanel.startGame();
			}
		});
		mnGameMenu.add(mntmNewGame);

		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		mnGameMenu.add(mntmExit);

		JMenu mnActions = new JMenu("Actions");
		menuBar.add(mnActions);

		JMenuItem mntmBank = new JMenuItem("Bank");
		mnActions.add(mntmBank);

		JMenuItem mntmBar = new JMenuItem("Bar");
		mnActions.add(mntmBar);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		locationPanel = new LocationPanel();
		contentPane.add(locationPanel, BorderLayout.SOUTH);
		game.addGameStateChangedListener(locationPanel);

		statusPanel = new StatusPanel();
		contentPane.add(statusPanel, BorderLayout.NORTH);
		game.addGameStateChangedListener(statusPanel);

		activityPanel = new ActivityPanel();
		contentPane.add(activityPanel, BorderLayout.CENTER);
		game.addGameStateChangedListener(activityPanel);

		marketplacePanel = new MarketplacePanel();
		contentPane.add(marketplacePanel, BorderLayout.WEST);
		game.addGameStateChangedListener(marketplacePanel);

	}
}
